﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using System.Drawing.Drawing2D;

namespace WonderfulSet
{
    class Methods
    {
        public static Card [] Forming()
        {
            //StreamReader spisok = new StreamReader("schedule.txt");
            Bitmap image3 = (Bitmap)Image.FromFile("clear.jpg");
            Card[] list = new Card [81];
            for (int i = 0; i < 81; i++ )
            {
                list[i] = new Card("rhomb", new Color(), new TextureBrush(image3), 0);
            }

            Bitmap image1 = (Bitmap)Image.FromFile("striped.jpg");
            Bitmap image2 = (Bitmap)Image.FromFile("solid.jpg");

            TextureBrush clear = new TextureBrush(image3);
            SolidBrush solid = new SolidBrush(Color.Black);
            HatchBrush striped = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Black, Color.White);

            SolidBrush solidN = new SolidBrush(Color.Black);
            HatchBrush stripedN = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Black, Color.White);
            list[0] = new Card("oval", Color.Red, clear, 1);
            list[1] = new Card("oval", Color.Red, clear, 2);
            list[2] = new Card("oval", Color.Red, clear, 3);
            list[3] = new Card("oval", Color.Red, solid, 1);
            list[4] = new Card("oval", Color.Red, solid, 2);
            list[5] = new Card("oval", Color.Red, solid, 3);
            list[6] = new Card("oval", Color.Red, striped, 1);
            list[7] = new Card("oval", Color.Red, striped, 2);
            list[8] = new Card("oval", Color.Red, striped, 3);
            list[9] = new Card("oval", Color.Green, clear, 1);
            list[10] = new Card("oval", Color.Green, clear, 2);
            list[11] = new Card("oval", Color.Green, clear, 3);
            list[12] = new Card("oval", Color.Green, solid, 1);
            list[13] = new Card("oval", Color.Green, solid, 2);
            list[14] = new Card("oval", Color.Green, solid, 3);
            list[15] = new Card("oval", Color.Green, striped, 1);
            list[16] = new Card("oval", Color.Green, striped, 2);
            list[17] = new Card("oval", Color.Green, striped, 3);
            list[18] = new Card("oval", Color.Blue, clear, 1);
            list[19] = new Card("oval", Color.Blue, clear, 2);
            list[20] = new Card("oval", Color.Blue, clear, 3);
            list[21] = new Card("oval", Color.Blue, solid, 1);
            list[22] = new Card("oval", Color.Blue, solid, 2);
            list[23] = new Card("oval", Color.Blue, solid, 3);
            list[24] = new Card("oval", Color.Blue, striped, 1);
            list[25] = new Card("oval", Color.Blue, striped, 2);
            list[26] = new Card("oval", Color.Blue, striped, 3);
            list[27] = new Card("rhomb", Color.Red, clear, 1);
            list[28] = new Card("rhomb", Color.Red, clear, 2);
            list[29] = new Card("rhomb", Color.Red, clear, 3);
            list[30] = new Card("rhomb", Color.Red, solid, 1);
            list[31] = new Card("rhomb", Color.Red, solid, 2);
            list[32] = new Card("rhomb", Color.Red, solid, 3);
            list[33] = new Card("rhomb", Color.Red, striped, 1);
            list[34] = new Card("rhomb", Color.Red, striped, 2);
            list[35] = new Card("rhomb", Color.Red, striped, 3);
            list[36] = new Card("rhomb", Color.Green, clear, 1);
            list[37] = new Card("rhomb", Color.Green, clear, 2);
            list[38] = new Card("rhomb", Color.Green, clear, 3);
            list[39] = new Card("rhomb", Color.Green, solid, 1);
            list[40] = new Card("rhomb", Color.Green, solid, 2);
            list[41] = new Card("rhomb", Color.Green, solid, 3);
            list[42] = new Card("rhomb", Color.Green, striped, 1);
            list[43] = new Card("rhomb", Color.Green, striped, 2);
            list[44] = new Card("rhomb", Color.Green, striped, 3);
            list[45] = new Card("rhomb", Color.Blue, clear, 1);
            list[46] = new Card("rhomb", Color.Blue, clear, 2);
            list[47] = new Card("rhomb", Color.Blue, clear, 3);
            list[48] = new Card("rhomb", Color.Blue, solid, 1);
            list[49] = new Card("rhomb", Color.Blue, solid, 2);
            list[50] = new Card("rhomb", Color.Blue, solid, 3);
            list[51] = new Card("rhomb", Color.Blue, striped, 1);
            list[52] = new Card("rhomb", Color.Blue, striped, 2);
            list[53] = new Card("rhomb", Color.Blue, striped, 3);
            list[54] = new Card("curve", Color.Red, clear, 1);
            list[55] = new Card("curve", Color.Red, clear, 2);
            list[56] = new Card("curve", Color.Red, clear, 3);
            list[57] = new Card("curve", Color.Red, solid, 1);
            list[58] = new Card("curve", Color.Red, solid, 2);
            list[59] = new Card("curve", Color.Red, solid, 3);
            list[60] = new Card("curve", Color.Red, striped, 1);
            list[61] = new Card("curve", Color.Red, striped, 2);
            list[62] = new Card("curve", Color.Red, striped, 3);
            list[63] = new Card("curve", Color.Green, clear, 1);
            list[64] = new Card("curve", Color.Green, clear, 2);
            list[65] = new Card("curve", Color.Green, clear, 3);
            list[66] = new Card("curve", Color.Green, solid, 1);
            list[67] = new Card("curve", Color.Green, solid, 2);
            list[68] = new Card("curve", Color.Green, solid, 3);
            list[69] = new Card("curve", Color.Green, striped, 1);
            list[70] = new Card("curve", Color.Green, striped, 2);
            list[71] = new Card("curve", Color.Green, striped, 3);
            list[72] = new Card("curve", Color.Blue, clear, 1);
            list[73] = new Card("curve", Color.Blue, clear, 2);
            list[74] = new Card("curve", Color.Blue, clear, 3);
            list[75] = new Card("curve", Color.Blue, solid, 1);
            list[76] = new Card("curve", Color.Blue, solid, 2);
            list[77] = new Card("curve", Color.Blue, solid, 3);
            list[78] = new Card("curve", Color.Blue, striped, 1);
            list[79] = new Card("curve", Color.Blue, striped, 2);
            list[80] = new Card("curve", Color.Blue, striped, 3);
            for (int i = 0; i < 81; i++)
            {
                if ((i < 9) || ((i > 26) && (i < 36)) || ((i > 53) && (i < 63)))
                {
                    stripedN = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Red, Color.White);
                    solidN = new SolidBrush(Color.Red);
                }
                if (((i > 8) && (i < 18)) || ((i > 35) && (i < 45)) || ((i > 62) && (i < 72)))
                {
                    stripedN = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Green, Color.White);
                    solidN = new SolidBrush(Color.Green);
                }
                if ((i >71) || ((i >44) && (i < 54)) || ((i > 17) && (i < 27)))
                {
                    stripedN = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Blue, Color.White);
                    solidN = new SolidBrush(Color.Blue);
                }
                if(list[i].Shade == solid)
                {
                    list[i].Shade = solidN;
                }
                if (list[i].Shade==striped)
                {
                    list[i].Shade = stripedN;
                    
                }
            }
            return list;//возвращает ArrayList
        }
        public static string IsSetShade(Card c, Card c1, Card c2)
        {
            string t = "t";
            string f = "f";
            string ng = "ng";
            if ((c.Shade == c1.Shade) && (c2.Shade == c1.Shade))
            {
                return t;
            }
            if ((c.Shade != c1.Shade) && (c2.Shade != c1.Shade) && (c.Shade != c2.Shade))
                return f;
            else
                return ng;
        }
        public static string IsSetShape(Card c, Card c1, Card c2)
        {
            string t = "t";
            string f = "f";
            string ng = "ng";
            if ((c.Shape == c1.Shape) && (c2.Shape == c1.Shape))
            {
                return t;
            }
            if ((c.Shape != c1.Shape) && (c2.Shape != c1.Shape) && (c.Shape != c2.Shape))

                return f;
            else
                return ng;
        }
        public static string IsSetColor(Card c, Card c1, Card c2)
        {
            string t= "t";
            string f = "f";
            string ng = "ng";
            if ((c.Color == c1.Color) && (c2.Color == c1.Color))
            {
                return t;
            }
            if ((c.Color != c1.Color) && (c2.Color != c1.Color) && (c.Color != c2.Color))

                return f;
            else
                return ng;
        }
        public static string IsSetNum(Card c, Card c1, Card c2)
        {
            string t = "t";
            string f = "f";
            string ng = "ng";
            if ((c.Number == c1.Number) && (c2.Number == c1.Number))
            {
                return t;
            }
            if ((c.Number != c1.Number) && (c2.Number != c1.Number) && (c.Number != c2.Number))

                return f;
            else
                return ng;
        }
        public static void SetActivity(int sum, Card[] masCards, ArrayList masActiveCards, ArrayList A, ArrayList masActivePB, PictureBox picb)
        {
            sum++;
            masActiveCards.Add(picb.Tag);
            Bitmap image3 = (Bitmap)Image.FromFile("clear.jpg");
            Color col = new Color();
            TextureBrush ex = new TextureBrush(image3);
            int n = 0;
            Card c = new Card("oval", col, ex, n);
            Card c1 = new Card("oval", col, ex, n);
            Card c2 = new Card("oval", col, ex, n);
            if (sum == 3)
            {

                c = (Card)masActiveCards[0];
                c1 = (Card)masActiveCards[1];
                c2 = (Card)masActiveCards[2];
                if ((Methods.IsSetColor(c, c1, c2) == "ng") || (Methods.IsSetNum(c, c1, c2) == "ng") || (Methods.IsSetShade(c, c1, c2) == "ng") || (Methods.IsSetShape(c, c1, c2) == "ng") || ((Methods.IsSetColor(c, c1, c2) == "f") && (Methods.IsSetNum(c, c1, c2) == "f") && (Methods.IsSetShade(c, c1, c2) == "f") && (Methods.IsSetShape(c, c1, c2) == "f")))
                {
                    MessageBox.Show("Not Set", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {

                    MessageBox.Show("Set", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    for (int i = 0; i < 3; i++)
                    {
                        c = (Card)masCards[(int)A[i]];
                        c.Draw((PictureBox)masActivePB[i]);
                        PictureBox pb = (PictureBox)masActivePB[i];
                        A.Remove(A[i]);
                        pb.Invalidate();
                    }
                }

                sum = 0;
                masActivePB.Clear();
                masActiveCards.Clear();
            }
        }
    }

    
}
